/**
*	Source: main.cpp
*	
*	This source file defines the entry point for the project and contains the game loop among
*	other things.
*	
*/

#include <string>
#include <fstream>
#include <SDL.h>
#include <libtcod.hpp>
#include "world.h"
#include "common.h"
#include "camera.h"

int main (int argc, char*argv[]) {
	FileIO fileio;
	fileio.loadSettings();
	fileio.loadDialogue("testdialogue.xml");
	Camera camera(gameSettings::windowX, gameSettings::windowY);

	TCODSystem::setFps(gameSettings::maxFPS); // limit framerate
	TCODConsole::initRoot (
		gameSettings::windowX,
		gameSettings::windowY,
		GAME_NAME,
		gameSettings::fullscreen
	);
	TCODConsole::root->setDefaultForeground(TCODColor::white);

	bool endGame = false;
	
	World world;

	while (!endGame && !TCODConsole::isWindowClosed()) {
		// ... draw on TCODConsole::root
		TCODConsole::root->clear();
		world.draw(&camera, TCODConsole::root);
		
		TCODConsole::flush();
		TCOD_key_t key =
			TCODConsole::checkForKeypress (TCOD_KEY_PRESSED|TCOD_KEY_RELEASED);
		// use elapsed to scale any update that is time dependent.
		world.update(key, TCODSystem::getLastFrameLength()); 
		world.updateViewport(&camera);
	}
	return 0;
}